<template>
	<view class="task_index_page">
		<image class="task_top_bk" :src="onlinePic+'task/task_top_bk.png'" mode="widthFix"></image>
		<view class="task_rules_box">
			<uni-icons type="info" size="10" color="#999999"></uni-icons>
			<view style="margin-left: 5rpx;" @click="goOildRule">集油规则</view>
		</view>
		<view class="oli_nums_box">
			<view class="oli_nums">{{integral}}L</view>
			<view class="display_flex">
				<view class="f-13" @click="goOilDetail">明细 ></view>
				<view class="f-13 ml-25" @click="goGiftList">礼品兑换 ></view>
			</view>
		</view>
		<view class="task_signin_box">
			<image class="task_signin_img" :src="onlinePic+'task/task_signin_img.png'" mode="widthFix"></image>
			<view class="task_signin_info">
				<view class="c-white">
					<view class="f-16">今日签到</view>
					<view class="f-11">连续签到有奖励</view>
				</view>
				<view class="flex-1">
					<image class="signin_tx_img" :src="onlinePic+'task/signin_tx_img.png'"></image>
				</view>
				<view v-if="sign_status==1" class="task_signin_btn_ok" @click="goSignin">已签到</view>
				<view v-else class="task_signin_btn" @click="goSignin">签到领油滴</view>
			</view>
		</view>
		<view class="task_cell_box">
			<view class="f-15">做任务赚油滴</view>
			<view v-for="(item,index) in tasklist" :key="item.name" class="task_cell">
				<image class="task_cell_icon" :src="picUrl+item.pic"></image>
				<view class="ml-10 flex-1">
					<view class="f-13">{{item.name}}</view>
					<view class="display_flex" style="margin-top: 6rpx;">
						<view class="task_oilnums">{{item.integral}}</view>
						<view class="f-10 c-999999 ml-10">{{item.remark}}</view>
					</view>
				</view>
				<view class="display_flex">
					<view class="f-12 c-999999">{{item.finish_number}}/{{item.number}}</view>
					<view v-if="item.status==0">
						<button v-if="item.path_type=='share'"
							@click="goPath(item.id,item.path,item.name,item.path_type)" open-type="share"
							class="task_status_no_btn ml-5">去完成</button>
						<view v-else @click="goPath(item.id,item.path,item.name,item.path_type)"
							class="task_status_no ml-5">
							去完成</view>
					</view>
					<view v-else class="task_status_ok ml-5">已完成</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getTaskList,
		getGroupUserInfo,
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				tasklist: [],
				integral: uni.getStorageSync('userinfo') ? uni.getStorageSync('userinfo').integral : 0,
				sign_status: uni.getStorageSync('userinfo') ? uni.getStorageSync('userinfo').sign_status : 0, //签到状态：0未，1已
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
			};
		},
		onShow() {
			if (uni.getStorageSync('access_token')) {
				this.getTaskList()
				this.getGroupUserInfo()
			} else {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		},
		onLoad() {
			var params = {
				event_code: '我的油滴',
				path: 'pages/taskcentre/index',
				event_id: '',
				title: '',
				source_page: '',
				value: '',
			}
			app.BurialPoint(params)
		},
		methods: {
			getGroupUserInfo() {
				getGroupUserInfo({
					user_id: uni.getStorageSync('userinfo') ? uni.getStorageSync('userinfo').user_id : ''
				}).then(res => {
					if (res.state == 1) {
						this.integral = res.data.list.integral
						this.sign_status = res.data.list.sign_status
						this.userinfo = res.data.list
						uni.setStorage({
							key: 'userinfo',
							data: res.data.list,
						});
					} else {
						uni.removeStorage({
							key: 'access_token'
						})
					}
				})
			},
			getTaskList() {
				getTaskList({
					user_id: this.user_id
				}).then(res => {
					if (res.state == 1) {
						this.tasklist = res.data.list
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			goOilDetail() {
				uni.navigateTo({
					url: '/pages/taskcentre/oildetail'
				})
				var params = {
					event_code: '我的油滴',
					path: 'pages/taskcentre/index',
					event_id: '',
					title: '',
					source_page: '我的油滴-明细',
					value: '',
				}
				app.BurialPoint(params)
			},
			goGiftList() {
				uni.navigateTo({
					url: '/pages/taskcentre/giftlist'
				})
				var params = {
					event_code: '我的油滴',
					path: 'pages/taskcentre/index',
					event_id: '',
					title: '',
					source_page: '我的油滴-礼品兑换',
					value: '',
				}
				app.BurialPoint(params)
			},
			goSignin() {
				uni.navigateTo({
					url: '/pages/signin/signin'
				})
				var params = {
					event_code: '我的油滴',
					path: 'pages/taskcentre/index',
					event_id: '',
					title: '',
					source_page: '我的油滴-签到领油滴',
					value: '',
				}
				app.BurialPoint(params)
			},
			goPath(id, path, name, type) {
				if (type == 'navigateTo') {
					uni.navigateTo({
						url: path
					})
				} else if (type == 'switchTab') {
					if(name=='点赞'||name=='发表评论'){
						uni.setStorage({
							key: 'taskType',
							data: 'true',
							success() {
								uni.switchTab({
									url: path
								})
							}
						})
					}else{
						uni.switchTab({
							url: path
						})
					}
					
				} else if (type == 'share') {
					this.share_path = path
				}
				var params = {
					event_code: '我的油滴',
					path: 'pages/taskcentre/index',
					event_id: '',
					title: '',
					source_page: '我的油滴做任务-' + name,
					value: '',
				}
				app.BurialPoint(params)
			},
			goOildRule() {
				uni.navigateTo({
					url: '/pages/taskcentre/taskrule'
				})
				var params = {
					event_code: '礼品兑换礼品列表',
					path: 'pages/taskcentre/giftlist',
					event_id: '',
					title: '',
					source_page: '礼品兑换礼品列表-集油规则',
					value: '',
				}
				app.BurialPoint(params)
			}
		},
		onPullDownRefresh() {
			uni.stopPullDownRefresh()
			this.getGroupUserInfo()
		},
		onShareAppMessage(res) {
			app.getShareTask()
			if (res.from === 'button') { // 来自页面内分享按钮
				return {
					path: this.share_url + '?invitation_id=' + this.user_id
				}
			} else {
				return {

				}
			}
		}
	}
</script>

<style lang="scss">
	.task_index_page {
		.task_top_bk {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: -1;
		}

		.task_rules_box {
			color: #999999;
			font-size: 20rpx;
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
		}

		.oli_nums_box {
			padding: 37rpx 50rpx;

			.oli_nums {
				color: #000000;
				font-size: 50rpx;
				font-weight: bold;
			}
		}

		.task_signin_box {
			position: relative;
			margin-top: 80rpx;
			margin-left: 50rpx;
			margin-right: 50rpx;


			.task_signin_img {
				width: 100%;
			}

			.task_signin_info {
				padding: 40rpx;
				display: flex;
				align-items: center;
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 1;

				.signin_tx_img {
					width: 96rpx;
					height: 95rpx;
					margin-left: 20rpx;
				}

				.task_signin_btn {
					width: 170rpx;
					height: 60rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #ffffff;
					font-size: 24rpx;
					border-radius: 30rpx;
					background-color: #00A0DC;
				}

				.task_signin_btn_ok {
					width: 170rpx;
					height: 60rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #ffffff;
					font-size: 24rpx;
					border-radius: 30rpx;
					background-color: #C5C5C5;
				}
			}
		}

		.task_cell_box {
			padding: 40rpx 50rpx;
			background-color: #FFFFFF;

			.task_cell {
				display: flex;
				align-items: center;
				padding: 30rpx 0;
				border-bottom: 1rpx solid #F1F1F1;

				.task_cell_icon {
					width: 75rpx;
					height: 75rpx;
					vertical-align: middle;
				}

				.task_oilnums {
					color: #00A0DC;
					font-size: 18rpx;
					padding: 1rpx 16rpx;
					border-radius: 4rpx;
					background-color: #E5F5FB;
					border: 1rpx solid #ADE9FF;
				}

				.task_status_ok {
					color: #999999;
					font-size: 20rpx;
					padding: 4rpx 10rpx;
					border-radius: 30rpx;
					background-color: #E6E6E6;
					border: 1rpx solid #C6C6C6;
				}

				.task_status_no {
					color: #00A0DC;
					font-size: 20rpx;
					padding: 4rpx 10rpx;
					border-radius: 30rpx;
					background-color: #FFFFFF;
					border: 1rpx solid #ADE9FF;
				}

				.task_status_no_btn {
					color: #00A0DC;
					font-size: 20rpx;
					padding: 4rpx 10rpx;
					border-radius: 30rpx !important;
					background-color: #FFFFFF;
					border: 1rpx solid #ADE9FF;
					line-height: normal;
					box-sizing: content-box;
				}

				button::after {
					border: 1rpx solid #ADE9FF !important;
					border-radius: 30rpx !important;
				}
			}

			.task_cell:last-child {
				border-bottom: none;
			}
		}
	}
</style>